package com.wwy.monitor.common;

public class ServiceResponse {
    private int code;
    private String message;
    private Object data;

    public ServiceResponse() {
    }

    public ServiceResponse(int code, String msg, Object data) {
        this.code = code;
        this.message = msg;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    private static ServiceResponse response(int code, String msg, Object data) {
        ServiceResponse resp = new ServiceResponse();
        resp.setCode(code);
        resp.setMessage(msg);
        resp.setData(data);
        return resp;
    }

    public static ServiceResponse paramEmpty(String errMsg) {
        return response(ResponseEnum.PARAM_EMPTY.getCode(), errMsg, null);
    }

    public static ServiceResponse paramIllegal(String errMsg) {
        return response(ResponseEnum.PARAM_ILLEGAL.getCode(), errMsg, null);
    }

    public static ServiceResponse fail(int errCode, String errMsg) {
        return response(errCode, errMsg, null);
    }

    public static ServiceResponse fail(int errCode, String errMsg, Object result) {
        return response(errCode, errMsg, result);
    }

    public static ServiceResponse success(Object data) {
        return response(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg(), data);
    }

    public static ServiceResponse success(String msg, Object data) {
        return response(ResponseEnum.SUCCESS.getCode(), msg, data);
    }

    public boolean isSuccess() {
        return this.code == ResponseEnum.SUCCESS.getCode();
    }

}
